# SPDX-FileCopyrightText: Adam Evyčędo
#
# SPDX-License-Identifier: AGPL-3.0-or-later

#!/bin/sh

# assumes ownership of /tmp/gtfs

mkdir /tmp/gtfs
cp "$1" /tmp/gtfs
cd /tmp/gtfs
unzip "$1"
printf 'translations '
if [ -e translations.txt ]; then
  printf 'YES\n'
else
  printf 'NO\n'
fi
printf 'frequencies  '
if [ -e frequencies.txt ]; then
  printf 'YES\n'
else
  printf 'NO\n'
fi
cat agency.txt routes.txt stops.txt | grep -o . | sort | grep -Pv '[\x61-\x7a\x41-\x5a0-9[:punct:][:space:]]' | uniq -c

for letter in $(cat agency.txt routes.txt stops.txt | grep -o . | sort -u | grep -Pv '[\x61-\x7a\x41-\x5a0-9[:punct:][:space:]]'); do
  echo "## $letter"
  grep -Ewo "[^ ]*$letter[^ ]*" agency.txt routes.txt stops.txt
done

cd - >/dev/null
rm -rf /tmp/gtfs
